package com.china.produce.service.impl;

import com.china.produce.mapper.study.UserMapper;
import com.china.produce.pojo.User;
import com.china.produce.pojo.user.LoginUser;
import com.china.produce.service.UserService;
import org.springframework.aop.framework.AopContext;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

/**
 * @ClassName
 * @Author niujie
 * @Version
 * @Description
 * @CreateTime 2022/4/2
 */
@Service
public class UserServiceImpl implements UserService {

    @Resource
    private UserMapper userMapper;

    @Override
    public User queryUserByName(LoginUser loginUser) {

        System.out.println(loginUser);

        new LoginUser("12", "12");

        try {
            TimeUnit.SECONDS.sleep(2);

        }catch (Exception exception) {

        }

       return new User();
    }


    public void updateUserByName(String name, String mobile) {

        ((UserService) AopContext.currentProxy()).execute(name, mobile);
    }

    @Transactional
    public void execute(String name, String mobile) {

        System.out.println("123+++--");

        userMapper.updateUserByName(name, mobile);

        userMapper.updateUserByName2(name, mobile);
    }

    @Override
    public void insertUser(String account, String password) {
        userMapper.insertAccount(account, password);
    }
}
